/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import java.awt.List;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.swing.JButton;
import vo.rb_users;

/**
 *
 * @author Shuhail
 */
public class RoyalStartUp extends javax.swing.JFrame {

    /**
     * Creates new form RoyalStartUp
     */
    public RoyalStartUp() {
        initComponents();
        addToList();
        this.cancelSelectedButton.setEnabled(false);
        logged_in_user.setText(users.getUser_name());
      //  jInternalFrame1.setVisible(false);
    }
    static {
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        R_raw_material = new javax.swing.JButton();
        R_employee = new javax.swing.JButton();
        R_vendor = new javax.swing.JButton();
        R_manufacture = new javax.swing.JButton();
        R_product = new javax.swing.JButton();
        R_purchase = new javax.swing.JButton();
        R_expense = new javax.swing.JButton();
        R_dealer = new javax.swing.JButton();
        R_track_expense = new javax.swing.JButton();
        R_sales = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        cancelSelectedButton = new javax.swing.JButton();
        raw_material_panel = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        logged_in_user = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        change_password_button = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Royal Batteries");
        setResizable(false);

        R_raw_material.setText("Raw Material");
        R_raw_material.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_raw_materialActionPerformed(evt);
            }
        });

        R_employee.setText("Employee");
        R_employee.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_employeeActionPerformed(evt);
            }
        });

        R_vendor.setText("Vendor");
        R_vendor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_vendorActionPerformed(evt);
            }
        });

        R_manufacture.setText("Manufacture");
        R_manufacture.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_manufactureActionPerformed(evt);
            }
        });

        R_product.setText("Product");
        R_product.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_productActionPerformed(evt);
            }
        });

        R_purchase.setText("Purchase");
        R_purchase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_purchaseActionPerformed(evt);
            }
        });

        R_expense.setText("Expense");
        R_expense.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_expenseActionPerformed(evt);
            }
        });

        R_dealer.setText("Dealer");
        R_dealer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_dealerActionPerformed(evt);
            }
        });

        R_track_expense.setText("Track Expense");
        R_track_expense.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_track_expenseActionPerformed(evt);
            }
        });

        R_sales.setText("Sales");
        R_sales.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                R_salesActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        cancelSelectedButton.setText("Cancel");
        cancelSelectedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelSelectedButtonActionPerformed(evt);
            }
        });

        raw_material_panel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton1.setText("Modify");
        raw_material_panel.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(94, 0, -1, 40));

        jButton2.setText("Add");
        raw_material_panel.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 0, -1, 40));

        jButton3.setText("Remove");
        raw_material_panel.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(189, -1, -1, 40));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(300, 300, 300)
                        .addComponent(cancelSelectedButton))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(raw_material_panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(529, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(raw_material_panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(259, 259, 259)
                .addComponent(cancelSelectedButton)
                .addContainerGap(291, Short.MAX_VALUE))
        );

        logged_in_user.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setText("logged in as :");

        change_password_button.setText("Change Password");
        change_password_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                change_password_buttonActionPerformed(evt);
            }
        });

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(R_employee, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(R_dealer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(R_raw_material, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
                    .addComponent(R_product, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(R_vendor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(R_expense, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(R_track_expense, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
                        .addComponent(R_sales, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(R_manufacture, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(R_purchase, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(change_password_button)
                .addGap(35, 35, 35)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(logged_in_user, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(76, 76, 76))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(logged_in_user, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(change_password_button))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(R_raw_material)
                        .addGap(18, 18, 18)
                        .addComponent(R_vendor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(R_product)
                        .addGap(18, 18, 18)
                        .addComponent(R_dealer)
                        .addGap(22, 22, 22)
                        .addComponent(R_employee)
                        .addGap(27, 27, 27)
                        .addComponent(R_expense)
                        .addGap(28, 28, 28)
                        .addComponent(R_purchase)
                        .addGap(27, 27, 27)
                        .addComponent(R_manufacture)
                        .addGap(18, 18, 18)
                        .addComponent(R_sales)
                        .addGap(18, 18, 18)
                        .addComponent(R_track_expense)))
                .addGap(29, 29, 29))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void R_raw_materialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_raw_materialActionPerformed
        // TODO add your handling code here:
        //R_dealer.setEnabled(false);
        //R_employee.setEnabled(false);
       
      //  butList.get("R_dealer").setEnabled(false);
        disableOthers(R_raw_material);
    }//GEN-LAST:event_R_raw_materialActionPerformed

    private void R_employeeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_employeeActionPerformed
        // TODO add your handling code here:
        disableOthers(R_employee);
    }//GEN-LAST:event_R_employeeActionPerformed

    private void R_vendorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_vendorActionPerformed
        // TODO add your handling code here:
        disableOthers(R_vendor);
        
    }//GEN-LAST:event_R_vendorActionPerformed

    private void R_manufactureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_manufactureActionPerformed
        // TODO add your handling code here:
        disableOthers(R_manufacture);
    }//GEN-LAST:event_R_manufactureActionPerformed

    private void R_productActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_productActionPerformed
        // TODO add your handling code here:
        disableOthers(R_product);
    }//GEN-LAST:event_R_productActionPerformed

    private void R_purchaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_purchaseActionPerformed
        // TODO add your handling code here:
        disableOthers(R_purchase);
    }//GEN-LAST:event_R_purchaseActionPerformed

    private void R_expenseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_expenseActionPerformed
        // TODO add your handling code here:
        disableOthers(R_expense);
    }//GEN-LAST:event_R_expenseActionPerformed

    private void R_dealerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_dealerActionPerformed
        // TODO add your handling code here:
        disableOthers(R_dealer);
    }//GEN-LAST:event_R_dealerActionPerformed

    private void R_track_expenseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_track_expenseActionPerformed
        // TODO add your handling code here:
        disableOthers(R_track_expense);
    }//GEN-LAST:event_R_track_expenseActionPerformed

    private void R_salesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_R_salesActionPerformed
        // TODO add your handling code here:
        disableOthers(R_sales);
    }//GEN-LAST:event_R_salesActionPerformed

    private void cancelSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelSelectedButtonActionPerformed
        // TODO add your handling code here:
        enableAllButtons();;
    }//GEN-LAST:event_cancelSelectedButtonActionPerformed

    private void change_password_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_change_password_buttonActionPerformed
        // TODO add your handling code here:
        
       // jInternalFrame1.setVisible(true);
    }//GEN-LAST:event_change_password_buttonActionPerformed
    private String string;

    /**
     * Get the value of string
     *
     * @return the value of string
     */
    public String getString() {
        return string;
    }

    /**
     * Set the value of string
     *
     * @param string new value of string
     */
    public void setString(String string) {
        this.string = string;
    }
    
    public void addToList() {
        butList =new HashMap<String, JButton>();
        butList.put("R_dealer", R_dealer);
        butList.put("R_employee", R_employee);
        butList.put("R_expense", R_expense);
        butList.put("R_manufacture", R_manufacture);
        butList.put("R_product", R_product);
        butList.put("R_purchase", R_purchase);
        butList.put("R_raw_material", R_raw_material);
        butList.put("R_sales", R_sales);
        butList.put("R_vendor", R_vendor);
        butList.put("R_track_expense", R_track_expense);
        
    }
    
    public void disableOthers(JButton but) {
        
     Iterator it=butList.entrySet().iterator();
     while(it.hasNext()) {
         
         Map.Entry pairs=(Map.Entry) it.next();
         JButton button=(JButton)pairs.getValue();
         if(button!=but) 
             button.setEnabled(false);
     }
     this.cancelSelectedButton.setEnabled(true);
    }
    
    public void setUser(rb_users u) {
        this.users=u;
    }
    public void enableAllButtons() {
        
        Iterator it=butList.entrySet().iterator();
        while(it.hasNext()) {
            Map.Entry pairs=(Map.Entry)it.next();
            JButton button=(JButton)pairs.getValue();
            button.setEnabled(true);
        }
        this.cancelSelectedButton.setEnabled(false);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RoyalStartUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RoyalStartUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RoyalStartUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RoyalStartUp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new RoyalStartUp().setVisible(true);
             
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton R_dealer;
    private javax.swing.JButton R_employee;
    private javax.swing.JButton R_expense;
    private javax.swing.JButton R_manufacture;
    private javax.swing.JButton R_product;
    private javax.swing.JButton R_purchase;
    private javax.swing.JButton R_raw_material;
    private javax.swing.JButton R_sales;
    private javax.swing.JButton R_track_expense;
    private javax.swing.JButton R_vendor;
    private javax.swing.JButton cancelSelectedButton;
    private javax.swing.JButton change_password_button;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel logged_in_user;
    private javax.swing.JPanel raw_material_panel;
    // End of variables declaration//GEN-END:variables

   private HashMap<String,JButton> butList;
   public static rb_users users;
           
           }
